package OSMS.dao;

import java.util.List;

import OSMS.entity.Boss;
import OSMS.entity.Order;
import OSMS.tools.JDBC_Util;

public class BossDao {

	//查询Boss表并返回List<Boss> 集合
	public List<Boss> BossList () throws Exception {
		String sql = "select * from boss" ;
		List<Boss> BossList = JDBC_Util.queryBeanList(sql, Boss.class);
		//调用JDBC中的queryBeanList方法获取学生表
		return BossList ;
	}
	
	//根据商家电话号码查找商家信息
	public List<Boss> getBossByTel(String btel) throws Exception {
		String sql = "select * from boss where btel = ?" ;
		List<Boss> BossList = JDBC_Util.queryBeanList(sql, Boss.class, btel);
		return BossList ;
	}
	
	//更新商家信息
	public boolean updateBoss(Boss boss) throws Exception {
		String sql = "update boss set bname=?,tel=?,baddress=?,bpwd=? where bid = ?" ;
		boolean flag = JDBC_Util.updateDb(sql,boss.getBname(),boss.getBtel(),boss.getBaddress(),boss.getBpwd(),boss.getBid());
		return flag; 
	}
	
	
    //新增商家
	public boolean insertBoss(Boss boss) {
		String sql = "insert into boss values(null,?,?,?,?)";
		boolean flag = JDBC_Util.updateDb(sql,boss.getBname(),boss.getBtel(),boss.getBaddress(),boss.getBpwd());
		return flag ;
	}
	
	//登录时使用，匹配数据库中的手机号和密码
	public Boss getBossWhenLogin(String btel,String bpwd) throws Exception{
		String sql = "select * from boss where btel = ? and bpwd = ?";
		Boss boss = null;
		boss = JDBC_Util.queryBean(sql, Boss.class,btel,bpwd);
		return boss;
	}
	

	/*7.13 刘艺杰新增
	 * 更改商家信息
	 * 
	 */
	public boolean upDateBossMsg(String bossname,String baddress,int bid) throws Exception{
		String sql = "update boss set bname = ?,baddress = ? where bid = ?";
		boolean flag = false;
		flag = JDBC_Util.updateDb(sql, bossname,baddress,bid);
		
		return flag;
	}
	
	//根据商家电话号码查找商家信息
	public Boss getBossById(int bid) throws Exception {
		String sql = "select * from boss where bid = ?" ;
		Boss boss = JDBC_Util.queryBean(sql, Boss.class, bid);
		return boss ;
	}
	
	//修改商家密码
	public boolean upDateBossPwd(String bpwd,int bid) throws Exception{
		String sql = "update boss set bpwd = ? where bid = ?";
		boolean flag = false;
		flag = JDBC_Util.updateDb(sql, bpwd,bid);
		return flag;
	}
	
	
	
	
}
